import { userLogin } from '@/api/user.js'
// 用户信息
export default {
  namespaced: true,
  state () {
    return {
      // 用户信息
      profile: {
        id: '',
        avatar: '',
        nickname: '',
        account: '',
        mobile: '',
        token: ''
      }
    }
  },
  mutations: {
    // 更新用户信息
    setUser (state, payload) {
      state.profile = payload
    },
    clearProfile (state) {
      state.profile = {}
      // state.profile = null  不要写null，写了null, profile.token就报错了
    }
  },
  actions: {
    async setLoginUser (xtx, obj) {
      const res = await userLogin(obj)
      console.log(res)
      xtx.commit('setUser', res.result)
    }
  }
}
